package net.xdclass.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import net.xdclass.enums.TaskStateEnum;
import net.xdclass.manager.TrafficManager;
import net.xdclass.manager.TrafficTaskManager;
import net.xdclass.mapper.TrafficMapper;
import net.xdclass.mapper.TrafficTaskMapper;
import net.xdclass.model.TrafficTaskDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TrafficTaskManagerImpl implements TrafficTaskManager {

    @Autowired
    private TrafficTaskMapper trafficTaskMapper;

    @Override
    public int add(TrafficTaskDO trafficTaskDO) {
        int rows = trafficTaskMapper.insert(trafficTaskDO);
        return rows;
    }

    @Override
    public TrafficTaskDO findByIdAndAccountNo(Long id, Long accountNo) {
        TrafficTaskDO trafficTaskDO = trafficTaskMapper.selectOne(new QueryWrapper<TrafficTaskDO>()
                .eq("account_no", accountNo)
                .eq("id", id));
        return trafficTaskDO;
    }

    @Override
    public int deleteByIdAndAccountNo(Long id, Long accountNo) {
        int rows = trafficTaskMapper.delete(new QueryWrapper<TrafficTaskDO>()
                .eq("account_no", accountNo)
                .eq("id", id)
        );
        return rows;
    }
}
